<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入
* Echarts (https://github.com/apache/echarts) 
* ol3Echarts (https://github.com/sakitam-fdd/ol3Echarts)
*********************************************************************-->
<html>
<head>
    <meta charset='utf-8'/>
    <title data-i18n="resources.title_echartsLinesMillions_railways"></title>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
    <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
    <script type="text/javascript" include="echarts,ol3-echarts"
            src="../../dist/ol/include-ol.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>
<body>
<div id='map'></div>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var tileURL = host + "/iserver/services/map-china/rest/maps/ChinaDark";

    var map = new ol.Map({
        target: 'map',
        // ol v7版本用法为ol.control.defaults.defaults； v6版本以下用法为ol.control.defaults
        controls: ol.control.defaults.defaults({attributionOptions: {collapsed: false}})
            .extend([new ol.supermap.control.Logo({ link: "https://iclient.supermap.io" })]),
        view: new ol.View({
            center: [106, 37.94],
            zoom: 5,
            projection: 'EPSG:4326',
            multiWorld: true
        }),
        layers: [new ol.layer.Tile({
            source: new ol.source.OSM({}),
            source: new ol.source.TileSuperMapRest({
                url: tileURL,
                prjCoordSys: {"epsgCode": 4326}
            }),
            projection: 'EPSG:4326'
        })]
    });

    var echartslayer = new EChartsLayer(null, {
        hideOnMoving: true,
        hideOnZooming: true
    });
    echartslayer.appendTo(map);
    var option = {
        progressive: 20000,
        title: {
            top: '10px',
            text: resources.text_echartsLinesMillions_railways,
            subtext: resources.text_echartsLinesMillions_railways_subtext,
            left: 'center',
            textStyle: {
                color: '#fff'
            },
            subtextStyle: {
                color: '#fff'
            }
        },
        series: [{
            type: 'lines',
            blendMode: 'lighter',
            dimensions: ['value'],
            data: new Float64Array(),
            polyline: true,
            large: true,

            lineStyle: {
                color: 'orange',
                width: 1,
                opacity: 0.3
            }
        }]
    };

    var CHUNK_COUNT = 19;

    function fetchData(idx) {
        if (idx > CHUNK_COUNT) {
            return;
        }
        var dataURL = "https://iclient.supermap.io/web/data/bigdata_railway_10w/data_" + idx + ".bin";
        var xhr = new XMLHttpRequest();
        xhr.open('GET', dataURL, true);
        xhr.responseType = 'arraybuffer';

        xhr.onload = function (e) {
            var rawData = new Float32Array(this.response);
            echartslayer.appendData({
                seriesIndex: 0,
                data: rawData
            });

            fetchData(idx + 1);
        };

        xhr.send();
    }

    echartslayer.setChartOptions(option);
    fetchData(0);

</script>
</body>
</html>